<?php
class Server {
  public static function get_objs($orm, $sys, $inst, $is_iframe) {
    $req = json_decode(Utils::get_param('req', '[]'));

    $tags = unserialize(A_HCS);
    
    $opts = new stdClass();
    if (isset($req->search->type) && isset($req->search->phrase)) {
      if ($req->search->type == 0) {
        $opts->cd = 't.tag_id LIKE :v0';
        $opts->cdv = array(':v0' => '%,' . A_HC . ',%');
      } else if ($req->search->type == 1) {
        $opts->cd = 't.tag_id LIKE :v0';
        $opts->cdv = array(':v0' => '%,' . $tags[$req->search->type - 1] . ',%');
      } else if ($req->search->type == 2) {
        $opts->cd = 't.tag_id LIKE :v0';
        $opts->cdv = array(':v0' => '%,' . $tags[$req->search->type - 1] . ',%');
      } else if ($req->search->type == 3) {
        $opts->cd = 't.tag_id LIKE :v0';
        $opts->cdv = array(':v0' => '%,' . $tags[$req->search->type - 1] . ',%');
      } else if ($req->search->type == 4) {
        $opts->cd = 't.tag_id LIKE :v0';
        $opts->cdv = array(':v0' => '%,' . $tags[$req->search->type - 1] . ',%');
      }
      
      $opts->cd .=  ' AND (t.title LIKE :v3)';
      $opts->cdv[":v3"] = '%' . $req->search->phrase . '%';
    }
      
    $res = $orm->get('pb_ecom_article', $req->o, $req->q, $req->pg, SIZE, $opts);
    echo json_encode($res);
  }
  
  public static function delete_obj($orm, $sys, $inst, $is_iframe) {
    $req = json_decode(Utils::get_param('req', '[]'));
    $orm->delete('pb_ecom_article', $req);
    if (isset($req->__pg)) {
      $res = $orm->get('pb_ecom_article', 't.date', 'DESC', $req->__pg, SIZE, NULL);
      echo json_encode($res);
    }
  }
}
?>